package com.ez.supervise.action.sys;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;

import com.ez.supervise.action.base.BaseJsonAction;
import com.ez.supervise.core.Page;
import com.ez.supervise.core.Result;
import com.ez.supervise.model.sys.User;
import com.ez.supervise.service.UserService;
import com.ez.supervise.util.JsonUtils;

public class EditPasswordAction extends BaseJsonAction {

    private static final long serialVersionUID = 967358559670907839L;

    private UserService userService;

   
    private Page page;

    private Long editUerId;

    private String oldPassword;

    private String newPassword;

    /**
     * 
     * @return
     */
    public String editPassword() {
	try {
	    User user = (User) userService.get(editUerId);
	    if(user != null && oldPassword.equals(user.getPassword())){
		user.setPassword(newPassword);
		userService.editPassword(user);
		Result result = new Result(user.getId());
		outJsonString(JSONObject.fromObject(result).toString());
	    } else {
		outJsonString(RESULT_FAIL);
	    }
	    
	} catch (Exception e) {
	    e.printStackTrace();
	    outJsonString(RESULT_FAIL);
	}
	return SUCCESS;
    }
    
    public Page getPage() {
	return page;
    }

    public void setPage(Page page) {
	this.page = page;
    }

    public Long getEditUerId() {
        return editUerId;
    }

    public void setEditUerId(Long editUerId) {
        this.editUerId = editUerId;
    }

    public void setNewPassword(String newPassword) {
	this.newPassword = newPassword;
    }

    public String getNewPassword() {
	return newPassword;
    }
    public String getOldPassword() {
        return oldPassword;
    }

    public void setOldPassword(String oldPassword) {
        this.oldPassword = oldPassword;
    }
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

}
